package org.sbbs.model;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;
import javax.persistence.Version;

/**
 * 实体类基类,所有的实体对象都应该实现如下方法: toString(), equals() and hashCode().
 */
@MappedSuperclass
public abstract class BaseEntity< PK extends Serializable> implements Serializable{ 

    protected PK pk;

    @Transient
    public abstract PK getId();

    public abstract void setId(PK id);

    @Transient
    protected PK getPk() {
        return this.pk;
    }

    public void setPk(PK pk) {
        this.pk = pk;
    }

    /**
     * 返回一个多行的字符串,它以 key=value 的形式呈现.
     *
     */
    public abstract String toString();

    /**
     * 比较对象是否相等.当使用Hibernate时,主键不应该成为比较的一部分.
     */
    public abstract boolean equals(Object o);

    /**
     * 当重载equals方法时,你相应的应该重载hashCode方法.至于为什么请看hibernate的文章,其有非常详尽的阐述.
     *
     * <dl>
     * <dt><b>参见：</b>
     * <dd><a href="https://developer.jboss.org/wiki/EqualsAndHashCode">Why are
     * equals() and hashCode() importation" for more information</a>
     * </dl>
     *
     */
    public abstract int hashCode();

    private Date lastModifyTime;

    @Version
    @Column(name = "LASTMODIFYTIME", nullable = true)
    public Date getLastModifyTime() {
        return lastModifyTime;
    }

    public void setLastModifyTime(Date lastModifyTime) {
        this.lastModifyTime = lastModifyTime;
    }

}
